package com.ck.ck_back.controller;

import okhttp3.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;

@RestController
public class get {

    @RequestMapping("/getopenid")
    public String getopenid(String code) throws IOException {
        OkHttpClient client = new OkHttpClient();
        RequestBody requestBody = new FormBody.Builder()
                .add("appid", "wxfacba1f06ce40ff5")
                .add("secret", "2e2668cee2f2005c9354dcf5c5679b67")
                .add("js_code",code)
                .add("grant_type","authorization_code")
                .build();
        Request request = new Request.Builder()
                .url("https://api.weixin.qq.com/sns/jscode2session")
                .method("Get",requestBody)
                .build();
        try (Response response = client.newCall(request).execute()) {
            return response.body().string();
        }
    }
}
